/**
 * @see https://leetcode-cn.com/problems/permutations/
 * 给定一个 没有重复 数字的序列，返回其所有可能的全排列。
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
  let i = 0;
  if(nums.length <= 1) {
    return [nums];
  }
  let innerResult = [];
  while (i < nums.length) {
    let sign = nums[i];
    let left = nums.slice(0, i).concat(nums.slice(i+1, nums.length));
    let loop = permute(left);
    console.log('递归完成', sign, loop)
    if(Array.isArray(loop)) {
      loop.forEach(item => {
        innerResult.push([sign].concat(item));
      })
      console.log('递归入栈结果', innerResult)
    }
    i++;
  }
  return innerResult;
};


console.log(permute([1,2,3]));